<template>
  <section class="cms-body" v-loading="loading">
    <!-- 返回组件 -->
    <cms-back></cms-back>
    <el-form ref="form" :model="dataInfo" :rules="rules" class="cms-form" label-width="162px">
      <el-form-item label="版本标识" class="flex-50" prop="verName">
        <el-input v-model="dataInfo.verCode" class="cms-width" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="版本名称" class="flex-50" prop="verName">
        <el-input v-model="dataInfo.verName" class="cms-width"></el-input>
      </el-form-item>
      <el-form-item label="版本标题" class="flex-50" prop="verTitle">
        <el-input v-model="dataInfo.verTitle" class="cms-width"></el-input>
      </el-form-item>
      <el-form-item label="版本号" class="flex-50" prop="verNo">
        <el-input v-model="dataInfo.verNo" class="cms-width"></el-input>
      </el-form-item>
      <el-form-item label="强制更新" class="flex-50" prop="forceUpdate">
        <el-radio-group v-model="dataInfo.forceUpdate">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="2">否</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="更新内容" class="flex-100" prop="verContent">
        <el-input type="textarea"  v-model="dataInfo.verContent" class="cms-width"></el-input>
      </el-form-item>
    </el-form>
    <div class="form-footer">
      <el-button type="primary" v-if="isType('update')" @click="update()" v-perms="'/keyword/update'">修改
      </el-button>
      <el-button type="info" @click="$reset">重置</el-button>
    </div>
  </section>
</template>
<script>
  import axios from "axios";
  import va from "@/rules";
  import formMixns from "@/mixins/form";

  export default {
    mixins: [formMixns],
    data() {
      let required = va.required();
      let number = va.number();
      return {
        rules: {//校验规则
          verName: [required],
          verTitle: [required],
          verNo: [required],
          verContent: [required],
          forceUpdate: [required],
        },
        dataInfo: {
          versionId: '',
          verName: '',
          verNo: '',
          verTitle: '',
          verContent: '',
          verUrl: '',
          verCode: '',
          forceUpdate: 2
        }
      };
    },
    methods: {
      getDataInfo(id, type) {
        if (type == 'update') {
          axios.post(this.$api.sysVersionGet, {versionId: id}).then(res => {
            if (res.code == '200') {
              this.dataInfo = res.body;
              this.$refs["form"].resetFields();
            }
            this.loading = false;
          })
        }
        this.loading = false;
      },
      update() {
        this.updateDataInfo(this.$api.sysVersionUpdate, this.dataInfo, "pageList");
      }
    },
    created() {
      //初始获取数据
      this.getDataInfo(this.id, this.type);
    }
  };
</script>

<style>
  .dialog .tree-layout {
    min-height: 400px;
    width: 90%;
  }

  .dialog .tree-layout .tree {
    width: 100%;
    height: 100%;
    overflow: auto;
    position: absolute;
    border-right: 0px solid #d4dde2;
  }

  .el-dialog__body {
    min-height: 450px;
    overflow: auto;
  }

  .red-color {
    color: red;
  }
</style>
